package com.doyoo.common;

import lombok.Data;

@Data
public class ResponseResult<T> {
    private Integer code;
    private String msg;
    private T data;

    public static <T> ResponseResult<T> newInstance(Integer code, String msg, T data) {
        ResponseResult<T> result = new ResponseResult<>();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

    public static <T> ResponseResult<T> success(String msg, T data) {
        return newInstance(HttpStatus.SUCCESS, msg, data);
    }

    public static <T> ResponseResult<T> success(T data) {
        return success("操作成功", data);
    }

    public static <T> ResponseResult<T> success() {
        return success(null);
    }

    public static <T> ResponseResult<T> error(Integer code, String msg) {
        return newInstance(code, msg, null);
    }

    public static <T> ResponseResult<T> error(String msg) {
        return error(HttpStatus.ERROR, msg);
    }

    public static <T> ResponseResult<T> error() {
        return error("操作失败");
    }
}
